package io.github.pigmesh.ai.deepseek.core.chat;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

import java.util.Objects;

@JsonDeserialize(builder = JsonArraySchema.Builder.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class JsonArraySchema extends JsonSchemaElement {

	@JsonProperty
	private final String description;

	@JsonProperty
	private final JsonSchemaElement items;

	public JsonArraySchema(Builder builder) {
		super("array");
		this.description = builder.description;
		this.items = builder.items;
	}

	@Override
	public boolean equals(Object another) {
		if (this == another)
			return true;
		return another instanceof JsonArraySchema && equalTo((JsonArraySchema) another);
	}

	private boolean equalTo(JsonArraySchema another) {
		return Objects.equals(description, another.description) && Objects.equals(items, another.items);
	}

	@Override
	public int hashCode() {
		int h = 5381;
		h += (h << 5) + Objects.hashCode(description);
		h += (h << 5) + Objects.hashCode(items);
		return h;
	}

	@Override
	public String toString() {
		return "JsonArraySchema{" + "description=" + description + ", items=" + items + "}";
	}

	public static Builder builder() {
		return new Builder();
	}

	@JsonPOJOBuilder(withPrefix = "")
	@JsonIgnoreProperties(ignoreUnknown = true)
	@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
	public static class Builder {

		private String description;

		private JsonSchemaElement items;

		public Builder description(String description) {
			this.description = description;
			return this;
		}

		public Builder items(JsonSchemaElement items) {
			this.items = items;
			return this;
		}

		public JsonArraySchema build() {
			return new JsonArraySchema(this);
		}

	}

}
